<?php
/**
* 用户中心
* @DateTime 2017-06-27
* @author xyl
*/
class User extends Admin_Controller
{
	
	function __construct()
	{
		parent::__construct();
		$this->load->model('User_model','user');  
		
	}
    /**
     * 注册用户首页
     * @DateTime 2017-06-27
     * @author xyl
     * @return   [type]     [description]
     */
    public function user()
    {
    	$ajaxUrl = base_url().'Admin/User/ajaxGetUserList';
    	if($_POST){
    		$data = $this->input->post();
    		if(isset($data['name'])){
    			$ajaxUrl = $ajaxUrl.'?'.'name='.$data['name'];
    			$vdata['search_name'] = $data['name'];
    		}else{
                // $ajaxUrl = $ajaxUrl.'?'.'status='.$data['status'].'&adviserid='.$data['adviser_id'].'&start_time='.$data['start_time'].'&end_time='.$data['end_time'];
            }
        }
        $vdata['ajaxUrl'] = $ajaxUrl;
        $this->load->view('User/user',$vdata);
    }

	/**
	 * ajax获取用户列表
     * @DateTime 2017-06-27
     * @author xyl * 
	 * @return [type] [description]
	 */
	public function ajaxGetUserList()
    {
		$where = $_GET;
		$user_list = $this->user->ajaxGetUserList($_GET['iDisplayLength'],$_GET['iDisplayStart'],$where);
		$return = array(
			'aaData'=>$user_list['data'],
			'iTotalRecords'=>count($user_list['data']),
			'iTotalDisplayRecords'=>$user_list['total'],
			);
		echo json_encode($return);
	}

	/**
     * 获取用户详细信息
     * @param  [string] $id     [用户id]1
     * @DateTime 2017-09-06
     * @author xyl
     * @return   [type]     [description]
     */
	public function userDetail($id,$type = false)
	{
        $vdata['user'] = $this->user->getUser(array("id"=>$id));
        if(!empty($type)) $vdata['type'] = 1;
        $vdata['user']['id'] = $id;
        $this->load->view('User/userDetail',$vdata);
    }

    /**
     * 用户信息更新
     * @param  [string] $id     [用户id]
     * @param  [type] $type   [类型 1主账号，2配偶]
     * @param  [type] $action [返回上一页的方法]
     * @DateTime 2017-06-30
     * @author xyl
     * @return   [type]     [description]
     */
    public function userUpdate($id)
    {
    	$post = $this->input->post();
    	$res = $this->user->updateUsersInfo($id,$post);
    	$this->handleResult($res);
    }

}